npx expo start
是用來啟動 Expo server。
terminal 提示 Expo 版本需要更新。
$ npx expo start
Starting project at D:\Jim\NotificationProgress
Starting Metro Bundler
The following packages should be updated for best compatibility with the installed expo version:
expo@51.0.32 - expected version: ~51.0.34
Your project may not work correctly until you install the expected versions of the packages.
Waiting on http://localhost:8081
Logs for your project will appear below.
使用 npm install expo@~51.0.34
更新版本。
接著用 npx expo run:android
建構 Android 專案。
$ npx expo run:android
› Building app...
Starting a Gradle Daemon (subsequent builds will be faster)
Configuration on demand is an incubating feature.
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> SDK location not found. Define a valid SDK location with an ANDROID_HOME environment variable or by setting the sdk.dir path in your project's local properties file at 'D:\Jim\NotificationProgress\android\local.properties'.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
BUILD FAILED in 38s
10 actionable tasks: 2 executed, 8 up-to-date
Error: D:\Jim\NotificationProgress\android\gradlew.bat app:assembleDebug -x lint -x test --configure-on-demand --build-cache -PreactNativeDevServerPort=8081 -PreactNativeArchitectures=arm64-v8a,armeabi-v7a exited with non-zero code: 1
Error: D:\Jim\NotificationProgress\android\gradlew.bat app:assembleDebug -x lint -x test --configure-on-demand --build-cache -PreactNativeDevServerPort=8081 -PreactNativeArchitectures=arm64-v8a,armeabi-v7a exited with non-zero code: 1
at ChildProcess.completionListener (D:\Jim\NotificationProgress\node_modules\@expo\spawn-async\build\spawnAsync.js:42:23)
at Object.onceWrapper (node:events:634:26)
at ChildProcess.emit (node:events:519:28)
at cp.emit (D:\Jim\NotificationProgress\node_modules\cross-spawn\lib\enoent.js:34:29)
at maybeClose (node:internal/child_process:1105:16)
at ChildProcess._handle.onexit (node:internal/child_process:305:5)
...
at spawnAsync (D:\Jim\NotificationProgress\node_modules\@expo\spawn-async\build\spawnAsync.js:7:23)
at spawnGradleAsync (D:\Jim\NotificationProgress\node_modules\@expo\cli\build\src\start\platforms\android\gradle.js:96:48)
at assembleAsync (D:\Jim\NotificationProgress\node_modules\@expo\cli\build\src\start\platforms\android\gradle.js:74:18)
at runAndroidAsync (D:\Jim\NotificationProgress\node_modules\@expo\cli\build\src\run\android\runAndroidAsync.js:45:37)
錯誤訊息顯示,在 android 目錄下的 local.properties 尚未使用 ANDROID_HOME 變數來指定 SDK 路徑。
回到專案資料夾,在 android 目錄下建立 local.properties 檔案。並添加下列 SDK 路徑。
sdk.dir=C\:\\Users\\User\\AppData\\Local\\Android\\Sdk
接著遇到 NDK 路徑未指定錯誤。
> Configure project :expo-modules-core
Warning: Failed to download any source lists!
Warning: Still waiting for package manifests to be fetched remotely.
FAILURE: Build failed with an exception.
* Where:
Script 'D:\Jim\NotificationProgress\node_modules\expo-modules-autolinking\scripts\android\autolinking_implementation.gradle' line: 408
* What went wrong:
A problem occurred evaluating project ':expo'.
> A problem occurred configuring project ':expo-modules-core'.
> NDK not configured. Download it with SDK manager. Preferred NDK version is '25.1.8937393'.
使用 IntelliJ IDEA 安裝對應版本的 NDK 後
在 local.properties 檔案 添加以下路徑。
ndk.dir=C\:\\Users\\User\\AppData\\Local\\Android\\Sdk\\ndk\\25.1.8937393